/**
  ******************************************************************************
  * @file	 bsp_PWM.c
  * @author  Wang Hongxi
  * @version V1.0.0
  * @date    2020/3/1
  * @brief   
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */
#include "bsp_PWM.h"

// void TIM_Set_PWM(TIM_HandleTypeDef *tim_pwmHandle, uint8_t Channel, uint16_t value)
// {
//     if (value > tim_pwmHandle->Instance->ARR)
//         value = tim_pwmHandle->Instance->ARR;

//     switch (Channel)
//     {
//     case TIM_CHANNEL_1:
//         tim_pwmHandle->Instance->CCR1 = value;
//         break;
//     case TIM_CHANNEL_2:
//         tim_pwmHandle->Instance->CCR2 = value;
//         break;
//     case TIM_CHANNEL_3:
//         tim_pwmHandle->Instance->CCR3 = value;
//         break;
//     case TIM_CHANNEL_4:
//         tim_pwmHandle->Instance->CCR4 = value;
//         break;
//     }
		
		
// }
void Set_Pwm(int16_t motor_a,int16_t motor_b)
{
	//Forward and reverse control of motor
	//电机正反转控制
	if(motor_a<0)			
    {
        __HAL_TIM_SET_COMPARE(&htim10,TIM_CHANNEL_1,-motor_a);
        __HAL_TIM_SET_COMPARE(&htim11,TIM_CHANNEL_1,0);
    }
    else{
        __HAL_TIM_SET_COMPARE(&htim10,TIM_CHANNEL_1,0);
        __HAL_TIM_SET_COMPARE(&htim11,TIM_CHANNEL_1,motor_a);
    }
	
	//Forward and reverse control of motor
	//电机正反转控制	
	if(motor_b<0)			
    {
        __HAL_TIM_SET_COMPARE(&htim9,TIM_CHANNEL_1,-motor_b);
        __HAL_TIM_SET_COMPARE(&htim9,TIM_CHANNEL_2,0);
    }
    else{
        __HAL_TIM_SET_COMPARE(&htim9,TIM_CHANNEL_1,0);
        __HAL_TIM_SET_COMPARE(&htim9,TIM_CHANNEL_2,motor_b);
    }
}